package com.qindian.coupontest;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

/**
 * Author: Li
 * Date: 2018/4/28 0028
 * Description:
 */

public class BaseActivity extends AppCompatActivity {

    protected Context mContext;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext=this;
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    private ProgressDialog mDialog;
    protected void showToast(String msg){
        Toast.makeText(BaseActivity.this, msg, Toast.LENGTH_SHORT).show();
    }

    protected void showLoadingDialog(String msg){
        if (mDialog == null) {
            mDialog=new ProgressDialog(BaseActivity.this);
        }
        mDialog.setMessage(msg);
        if (!mDialog.isShowing()) {
            mDialog.show();
        }

    }

    protected void showLoadingDialog(){
        showLoadingDialog("加载中...");
    }
    protected void dismissLoadingDialog(){
        if (mDialog != null && mDialog.isShowing()) {
            mDialog.dismiss();
        }
    }

    @Override
    protected void onDestroy() {
        dismissLoadingDialog();
        super.onDestroy();
    }

}
